﻿/* 自定义的WinKawaks的通用热键模块,需要指定暂停,即使存档读档,变更即使存档读档的热键,所以需要新建实例才能使用
  By setycyas @2023-01-31
*/

class MyWinKawaks {

  ;静态常量,指定winkawaks的exe名称
  static EXE := "winkawaks.exe"
  
  ;实例变量
  _pauseKey := "" ;暂停热键
  _stateSaveKey := "" ;即时存档热键
  _stateLoadKey := "" ;即时读档热键
  _nextStateKey := "" ;下一个存档位置热键
  _lastStateKey := "" ;上一个存档位置热键

  __New(pauseKey := "numpad0", stateSaveKey := "delete", stateLoadKey := "PGDN", nextStateKey := "PGUP", lastStateKey := "Home"){
    local wTitle := "ahk_exe " . MyWinkawaks.EXE ;窗口标题
    local funPause, funStateSave, funStateLoad, funNextState, funLastState ;绑定用函数对象,必须如此,而不能直接在绑定热键时一串表达式
    this._pauseKey := pauseKey ;暂停热键
    this._stateSaveKey := stateSaveKey ;即时存档热键
    this._stateLoadKey := stateLoadKey ;即时读档热键
    this._nextStateKey := nextStateKey ;下一个存档位置热键
    this._lastStateKey := lastStateKey ;上一个存档位置热键
    ;绑定热键
    funPause := this._pauseToggle.bind(this)
    funStateSave := this._stateSave.bind(this)
    funStateLoad := this._stateLoad.bind(this)
    funNextState := this._nextState.bind(this)
    funLastState := this._lastState.bind(this)
    Hotkey, IfWinActive, %wTitle%
    Hotkey, ~%pauseKey%, % funPause
    Hotkey, ~%stateSaveKey%, % funStateSave
    Hotkey, ~%stateLoadKey%, % funStateLoad
    Hotkey, ~%nextStateKey%, % funNextState
    Hotkey, ~%lastStateKey%, % funLastState
    Hotkey, IfWinActive
  }

  /* 私有函数,用于绑定各个按键的响应 
  */
  
  _pauseToggle(){
    send {enter down}{enter up}
  }
  _stateSave(){
    send, {F5 down}{F5 up}
  }
  _stateLoad(){
    send, {F7 down}{F7 up}
  }
  _nextState(){
    send, {F8 down}{F8 up}
  }
  _lastState(){
    send, {F6 down}{F6 up}
  }

}

/* 测试
new MyWinkawaks()
*/